typedef float hrilFloat;

template <typename T>
inline T clamp(T val, T min, T max)
{
    if (val < min)
        return min;
    else if (val > max)
        return max;
    return val;
}

template <typename T>
inline int sign(T val)
{
    return val > 0 ? 1 : -1;
}

template <typename T>
inline T wrap(T val, T max)
{
    T tmp = val % max;
    return tmp >= 0 ? tmp : tmp + max;
}

inline __host__ __device__ hrilFloat dist(const hrilFloat a[2], const hrilFloat b[2])
{
    return sqrt((a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1])); 
}

inline double get_time()
{
    timeval tim;
    gettimeofday(&tim, NULL);
    return tim.tv_sec + (double)tim.tv_usec/1000000.0;
}
